#ifndef STORAGE_H_
#define STORAGE_H_

#include <string.h>
#include <assert.h>
#include <stdbool.h>
//#include <cross_studio_io.h>
#ifndef S_SPLINT_S
#include "ff.h"
#endif

#define STORAGE_FILE "0:storage.txt"

typedef enum {
  STORAGE_OK = 1,
  STORAGE_EMPTY,
  STORAGE_ERROR,
} STORAGE_RESULT_t;

#define STORAGE_HEADER_CHECKSUM 0x0a0dbeef

typedef struct  {
  unsigned int  available;          // Total records available
  unsigned int  sent;               // Total records sent from storage
  unsigned long next;      // Pointer in file to a next record to send 
  unsigned int  checksum;  // Should be 0x0a0dbeef
} storage_header_t;

typedef struct {
  FIL file;
  storage_header_t header;
} storage_record_iterator;

STORAGE_RESULT_t storage_puts(char* src, unsigned int length);
STORAGE_RESULT_t storage_gets(char* dest, unsigned int* length, bool mark_as_read);

#endif /* STORAGE_H_ */